package com.sxz.sbs.module.amortize.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.amortize.AmortizeBankBean;
import com.sxz.sbs.module.client.bean.AllHousesBean;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;
import java.util.List;

/**
 * @author : tian
 *         time   : 2018/03/22
 *         desc   :
 */

public class AmortizeCalculatorPresenter extends RxPresenter<AmortizeCalculatorView>{
    /**
     * 获取所有楼盘
     * @param map
     * @param isAll 是否是所有案场   false  查看员工所在案场
     */
    public void getAllHouses (HashMap<String,Object> map, boolean isAll) {
        if (isAll) {
            addSubscribe(App.getInstance().getApi().getAllHouses(map)
                    .compose(RxUtil.<AllHousesBean>handleResult())
                    .subscribeWith(new RxSubscriber<AllHousesBean>(mView){
                        @Override
                        public void onNext(AllHousesBean data) {
                            mView.onGetHousesDataSuccess(data);
                        }
                    })
            );
        } else {
            addSubscribe(App.getInstance().getApi().getMyParking(map)
                    .compose(RxUtil.<AllHousesBean>handleResult())
                    .subscribeWith(new RxSubscriber<AllHousesBean>(mView){
                        @Override
                        public void onNext(AllHousesBean data) {
                            mView.onGetHousesDataSuccess(data);
                        }
                    })
            );
        }

    }
    public void getBank(HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getBank(map)
                .compose(RxUtil.<List<AmortizeBankBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<AmortizeBankBean>>(mView){
                    @Override
                    public void onNext(List<AmortizeBankBean> data) {
                        mView.onGetBankDataSuccess(data);
                    }
                })
        );
    }
}
